const co = require('co');
const OSS = require('ali-oss');
const client = new OSS({
    region: 'oss-cn-shanghai',
    accessKeyId: 'LTAIshyP8Q5XNPw9',
    accessKeySecret: 'jTq3LnlrDlSdNRQzmN1jFBvCfU7v8E'
});
client.useBucket('smtoolfile');

module.exports = {
    upload:function (uniqueFileName,fileObject) {
        return co(function* () {
            return yield client.put('2017/'+uniqueFileName, fileObject);
        });
    },
    delete:function (uniqueFileName) {
        return co(function* () {
            return yield client.delete('2017/'+uniqueFileName);
        });
    },
    deleteMulti:function (uniqueFileNames) {
        let keys = [];
        uniqueFileNames = uniqueFileNames || [];
        uniqueFileNames.forEach(function (ele) {
            keys.push('2017/'+ ele);
        });
        return co(function* () {
            return yield client.deleteMulti(keys, {
                quiet: true
            });
        });
    }
};